package com.china08.yxyapi.api.home.activity.marker;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.maker.YxyMakerCatalog;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.marker.YxyMakerCatalogRepository;

/**
 * 区县教育局-竞赛报名-竞赛项目查询
 * 
 * @author zd.Jin
 *
 *
 */
@RestController
@CrossOrigin
public class YxyMakerCatalogSrhController extends YxyApiBaseController {
    @Autowired
    private YxyMakerCatalogRepository yxyMakerCatalogRepository;

    @RequestMapping(value = "/api_yw/home/activity/competition/catalog/srh", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel process(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel reqModel) {
        RespModel respModel = new RespModel();

        YxyMakerCatalog cat = yxyMakerCatalogRepository.findOne(reqModel.id);
        YxyMakerCatalog pcat = yxyMakerCatalogRepository.findOne(cat.getPid());
        respModel.id = cat.getId();
        respModel.pid = cat.getPid();
        respModel.name = cat.getName();
        respModel.pname = pcat.getName();
        respModel.phase = cat.getPhase();
        respModel.phasename = cat.getPhaseName();
        return respModel;
    }

    protected static class ReqModel extends YxyApiReqModel {

        public String id;// 创客分类id

        public void check() {
            Assert.notNull(StringUtils.defaultIfBlank(id, null), "创客分类的id不能为空");
        }

    }

    protected static class RespModel extends YxyApiRespModel {
        // 创客分类id
        public String id;
        // 创客分类pid
        public String pid;
        // 创客分类的名称
        public String name;
        // 创客分类的父类名称
        public String pname;
        // 创客分类的学段code
        public String phase;
        // 创客分类的学段名称
        public String phasename;
    }
}
